package script.grammar.expression;

import script.grammar.symbol.Type;

public abstract class BinaryOperator implements Operator {
	private final String name;
	
	public BinaryOperator(String name) {
		this.name = name;
	}
	
	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public int getArity() {
		return 2;
	}

	@Override
	public Type computeType(Type... operands) {
		if (operands.length != 2) {
			throw new IllegalArgumentException();
		}
		return computeTypeImpl(operands[0], operands[1]);
	}
	
	protected abstract Type computeTypeImpl(Type o1, Type o2);
}
